#include "BleServerConnector.h"
#include "USBClientConnector.h"

#include "hid.h"
#include <Arduino.h>

#ifndef _HID_PS2_conv_H
#define _HID_PS2_conv_H

#define HID_COUNT 5 // 允许的USB+BLE设备总数

class HIDPS2conv;

class HIDPS2conv_HIDPoint {
public:
    int type = 0;          // 连接种类 0:empty ; 1 BLE; 2 USB
    int keyboard_mode = 0; // 0: 美式键盘; 1:日式键盘
    HID hid;

    // 蓝牙设备
    BleServerConnector *pBleServerConnector = nullptr;
    BLERemoteCharacteristic *pReadReportCharacteristic = nullptr;

    // USB设备
    USBClientConnector *pUSBClientConnector = nullptr;
};

class HIDPS2conv : public BleServerConnectorCallbacks, public USBClientConnectorCallbacks {
protected:
    static HIDPS2conv_HIDPoint s_hidPoint[HID_COUNT];

public:
    void ble_onConnect(BleServerConnector *pBleServerConnector, BLERemoteService *pRemoteService, bool &flag);
    void ble_onDisconnect(BleServerConnector *pBleServerConnector);
    void ble_bindReadReportCharacteristic(BleServerConnector *pBleServerConnector, BLERemoteCharacteristic *_pReadReportCharacteristic);

    virtual void onRecvDataHID(int num, uint8_t *dataBuf, int nLen);

    static HIDPS2conv_HIDPoint *addHidDevice(BleServerConnector *pConnector);
    static HIDPS2conv_HIDPoint *addHidDevice(USBClientConnector *pConnector);
    static void removeHidDevice(BleServerConnector *pConnector);
    static void removeHidDevice(USBClientConnector *pConnector);

    friend HIDPS2conv_HIDPoint *getDevices();
    friend void saveConfig();
};

#endif
